package thread.demo04.notify;

public class Test {
	public static void main(String[] args) throws Exception {

		final MyQueue myQueue = new MyQueue();
		initMyQueue(myQueue);

		Thread t1 = new Thread(() -> {
			myQueue.put("5");
			myQueue.put("6");
			myQueue.put("7");
			myQueue.put("8");
			myQueue.put("9");
		}, "t1");

		Thread t2 = new Thread(() -> {
			try {
				myQueue.get();
				myQueue.get();
				Thread.sleep(1000);
				myQueue.get();
				myQueue.get();
				myQueue.get();
				Thread.sleep(1000);
				myQueue.get();
				myQueue.get();
				Thread.sleep(1000);
				myQueue.get();
				myQueue.get();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}, "t2");

		t1.start();
		Thread.sleep(1000);
		t2.start();

	}

	private static void initMyQueue(MyQueue myQueue) {
		myQueue.put("1");
		myQueue.put("2");
		myQueue.put("3");
		myQueue.put("4");
		System.out.println("当前元素个数：" + myQueue.size());
	}
}
